<?php
	
	
	function subtractDate($date1, $date2, $option) {
		//days years months
		$year1=substr($date1, 0, 4);
		$month1=substr($date1, 5, 2);
		$day1=substr($date1, 8, 2);
		$year2=substr($date2, 0, 4);
		$month2=substr($date2, 5, 2);
		$day2=substr($date2, 8, 2);
		
		//$sum=$month1." and ".$month2;
		//echo $sum;
		
		if($day1<$day2){
			$day1+=30;
			$month1-=1;
		}
		$days=$day1-$day2;
		
		if($month1<$month2){
			$month1+=12;
			$year1-=1;
		}
		$months=$month1-$month2;
		$years=$year1-$year2;
		
		if($option=="year") {
			return $years;
		}else if($option=="month"){
			return $months;
		}else{
			return $days;
		}	
	}
	
	function compute($endDate, $originalAppointment){//with pay  p lng
		$year=subtractDate($endDate, $originalAppointment, 'year');
		$month=subtractDate($endDate, $originalAppointment, 'month');
		$day=subtractDate($endDate, $originalAppointment, 'day');
		//echo $year."-".$month."-".$day;
		
		$yearcredits=(150*$year)/10;
		$monthcredits=(15*$month)/12;
		$daycredits=(1.25*$day)/30;
		
		$sum=$yearcredits+$monthcredits+$daycredits;
		echo $sum;//total balance with no subtraction
		
		////////////////////////////////
		//day by day increment
		/////////////////////////////////
		
		$r1=getLeaveData();
		while ($data = mysql_fetch_assoc($r1))
		{
			$endDate = $data['End_date'];
			
		}
		//ilipat s LeaveManager
		$link = makeSQLconnection();

		$query=sprintf("SELECT DATEDIFF(CURDATE(), '$endDate') FROM `LEAVEFORM`"); 
		$return = mysql_query($query, $link);
		
		$return*=0.042;
		$return+=compute();
	}
	
	compute('2011-03-24','2010-10-29');
?>